import { request } from '@/utils/http'
import {
  ReqGetHospitalListParams,
  ReqGetHospitalListResponse,
  ProvinceList,
  HospitalDetailType,
  DepartmentList,
  ReqGetScheduleRuleListParams,
  ReqGetScheduleRuleListRespone,
  ReqGetScheduleListParams,
  ScheduleList,
  Status
} from './model/hospitalListTypes'

// 获取医院列表的请求
// page 和 limit 走的是路径，其他人走的是查询query
export function reqGetHospitalList({
  page,
  limit,
  ...formParams
}: ReqGetHospitalListParams) {
  // get 请求需要写在 params 字段中
  return request.get<any, ReqGetHospitalListResponse>(
    `/hos/admin/hosp/hospital/${page}/${limit}`,
    { params: formParams }
  )
}


// --- 表单查询的请求函数 --------------------------------
export const reqGetProvinceiList = (areaId = 'province') => {
  return request.get<any, ProvinceList>(
    `/data/admin/cmn/dict/findByDictCode/${areaId}`
  )
}

// 获取市区数据
export const reqGetCityOrQuXianList = (parentId: number) => {
  return request.get<any, ProvinceList>(
    `/data/admin/cmn/dict/findByParentId/${parentId}`
  )
}

// 获取医院详情
export const reqGetHospitalDetail = (id: string) => {
  return request.get<any, HospitalDetailType>(
    `/hos/admin/hosp/hospital/show/${id}`
  )
}

// -- 获取科室，排班规则信息，排班信息 -------------------
// 获取医院科室数据
export const reqGetDepartmentList = (hoscode: string) => {
  return request.get<any, DepartmentList>(
    `/hos/admin/hosp/department/${hoscode}`
  )
}

// 获取排班规则数据
export const reqGetScheduleRuleList = ({
  page, limit, hoscode, depcode
}: ReqGetScheduleRuleListParams) => {
  return request.get<any, ReqGetScheduleRuleListRespone>(
    `/hos/admin/hosp/schedule/getScheduleRule/${page}/${limit}/${hoscode}/${depcode}`
  )
}

// 获取详细医生的排班数据
export const reqGetScheduleList = ({
  hoscode, depcode, workDate
}: ReqGetScheduleListParams) => {
  return request.get<any, ScheduleList>(
    `/hos/admin/hosp/schedule/findScheduleList/${hoscode}/${depcode}/${workDate}`
  )
}

// --- 上线和下线切换  -----------------
// 医院上线
export const reqUpdateHospitalStatus = (id: string, status: Status) => {
  // Status 0 未上线 | 1  已上线
  return request.get<any, null>(
    `/hos/admin/hosp/hospital/updateStatus/${id}/${status}`
  )
}